<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 数据表格 -->
      <table id="dataTable2" lay-filter="dataTable2"></table>
    </div>
  </div>
</div>
<style>
  .layui-table-box {
    overflow: auto !important;
  }
</style>
<script>
  layui.use(['layer', 'table', 'tableX', 'notice', 'xnUtil', 'laydate'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var table = layui.table;
    var tableX = layui.tableX;
    var admin = layui.admin;
    var form = layui.form;
    var notice = layui.notice;
    var xnUtil = layui.xnUtil;
    var laydate = layui.laydate;

    //监听选中的用户
    var userData = [];
    /* 渲染表格 */
    var insTb = tableX.render({
      elem: '#dataTable2',
      url: getProjectUrl() + 'sysUser/page',
      page: true,
      toolbar: ['<p>',
        '<button lay-event="add" perm-show="singleelection:add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe654;</i>选择</button>&nbsp;',
        '</p>'].join(''),
      defaultToolbar:[],
      cellMinWidth: 100,
      checkStatus:true,
      cols: [
        [
          {type: 'checkbox'},
          {field: 'id', title: 'id', hide: true, sort: true},
          {field: 'sysEmpInfo.orgId', title: 'orgId', hide: true, sort: true, templet: function (d) {if(d.sysEmpInfo){return d.sysEmpInfo.orgId;}else {return "";}}},
          {field: 'account', title: '账号', sort: true, align: 'center', width: 200, minWidth: 200},
          {field: 'name', title: '姓名', sort: true, align: 'center', width: 200, minWidth: 200},
          {field: 'sex', title: '性别', sort: true, align: 'center', width: 120, minWidth: 120, templet: function (d) {return xnUtil.rendDataTableDict(d.sex, 'sex');}},
          {field: 'phone', title: '手机', sort: true, align: 'center', width: 200, minWidth: 200},
          {field: 'status', title: '状态', sort: true, align: 'center', width: 120, minWidth: 120, templet: function (d) {return '<a style="color:#1e90ff;cursor: pointer" lay-event="changeStatus">' + xnUtil.rendDataTableDict(d.status, 'common_status') + '</a>';}},
        ]
      ],
      done: function(res, curr, count) {
        xnUtil.tableDone(insTb, res, curr, count);
        debugger;
        for (var i = 0;i < userData.length;i++){
          //if (userData[i] == t_contract.USERID) {
            //$('div.layui-unselect.layui-form-radio')[i].click();//单选用这个
             $('div.layui-unselect.layui-form-checkbox')[1].click();
            break;
          //}
        }
      }
    });

    table.on('checkbox(dataTable2)',function (obj) {
      debugger;
      if(obj.checked){
        userData.push(obj.data.id);
        userData = Array.from(new Set(userData));
      }
    });


    /* 表格搜索 */
    form.on('submit(tableSearch)', function (data) {
      insTb.reload({where: data.field, page: {curr: 1}});
      return false;
    });

    /* 表格头工具栏点击事件 */
    table.on('toolbar(dataTable)', function (obj) {
      if (obj.event === 'add') { // 添加
        var checkRows = table.checkStatus('dataTable1');
        admin.putLayerData('formOk', true, '#dataTable1');
        admin.putLayerData('resultData', checkRows.data, '#dataTable1');
        admin.closeDialog('#dataTable1');
      }
    });

  });
</script>
